<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8"%>
<jsp:forward page="../client?action=PageManage"></jsp:forward>
<html>
<head>
    <meta charset="UTF-8">
    <title>Welcome</title>
    <base href="${pageContext.request.scheme}://${pageContext.request.serverName}:${pageContext.request.serverPort}${pageContext.request.contextPath}/pages/Welcome.jsp"/>
    <style>
        h2{
            color:red;
            font-size: 40px;
            text-align: center;
        }
        .books{
            height: 200px;
            width:300px;
            text-align: left;
            margin-top:5px;
            float:left;
            margin-right: 60px;
            border:solid 1px green;
        }
        #div3{
            margin-top:645px;
            text-align: center;
        }
        #div2{
            margin:0 auto;
            text-align: center;
        }
    </style>
    <script type="text/javascript" src="../Jquery/jquery-1.8.3.js"></script>
    <script type="text/javascript">
        $(function() {
            $("#bu1").click(function() {
                var pageNo=$("#skip").val();
                var pageTotal=$("#pageT");
                if(pageNo<1||pageNo>pageTotal){
                    alert("非法输入，请重新输入!");
                }else {
                    var pageSize = $("#pageS").val();
                    location.href = "${pageContext.request.scheme}://${pageContext.request.serverName}:${pageContext.request.serverPort}${pageContext.request.contextPath}/client?action=PageManage&pageNow=" + pageNo + "&pageSize=" + pageSize
                        +"&begin=${param.begin}&end=${param.end}";
                }
            });
        });
    </script>
    <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
</head>
<body>

<h2>书城首页</h2>
<%@include file="../publicPages/UserInfo.jsp"%><br/><br/><br/>
<div id="div2">
    <form action="../client" method="post" name="priceQuery">
        <input type="hidden" value="PageManageByPrice" name="action"/>
        按价格搜索:<input type="text" name="begin" value="${param.begin}"/>元 - <input type="text" name="end" value="${param.end}"/>元
        <input type="submit" value="确定"/>
    </form>
</div>
<c:forEach items="${bookss}" var="book">
<div class="books">
    <img src="kun.jpg"/><br/>
    <span>书名:${book.name}</span><br/>
    <span>作者:${book.author}</span><br/>
    <span>价格:${book.price}</span><br/>
    <span>销量:${book.sale}</span><br/>
    <span>库存:${book.stock}</span><br/>
</div>
</c:forEach><br/>
<div id="div3">
    <c:if test="${pages.pageNow!=1}">
        <a href="../client?action=PageManage&pageNow=1&pageSize=${pages.pageSize}">首页</a>
        <a href="../client?action=PageManage&pageNow=${pages.pageNow-1}&pageSize=${pages.pageSize}">上一页</a>
    </c:if>
    <form action="../client?action=PageManage" method="post" name="pageInfo">
        当前页码:<input type="text" name="pageNow" value="${pages.pageNow}"/>&nbsp;&nbsp;&nbsp; 每页记录条数:<input type="text" name="pageSize" value="${pages.pageSize}"/>
        <input type="submit" value="刷新"/>
    </form>
    <c:if test="${pages.pageNow!=pages.pageTotal}">
        <a href="../client?action=PageManage&pageNow=${pages.pageNow+1}&pageSize=${pages.pageSize}">下一页</a>
        <a href="../client?action=PageManage&pageNow=${pages.pageTotal}&pageSize=${pages.pageSize}">末页</a>
    </c:if>
    总页码:${pages.pageTotal}&nbsp;&nbsp;&nbsp;总记录数:${pages.countTotal}<br/>
    <c:choose>
        <c:when test="${pages.pageTotal<=5}">
            <c:forEach begin="1" end="${pages.pageTotal}" var="i">
                <c:if test="${pages.pageNow==i}">
                    第【${i}】页
                </c:if>
                <c:if test="${pages.pageNow!=i}">
                    <a href="../client?action=PageManage&pageNow=${i}&pageSize=${pages.pageSize}">第${i}页</a>
                </c:if>
            </c:forEach>
        </c:when>
        <c:otherwise>
            <c:choose>
                <c:when test="${pages.pageNow==1||pages.pageNow==2}">
                    <c:forEach begin="1" end="5" var="i">
                        <c:if test="${pages.pageNow==i}">
                            第【${i}】页
                        </c:if>
                        <c:if test="${pages.pageNow!=i}">
                            <a href="../client?action=PageManage&pageNow=${i}&pageSize=${pages.pageSize}">第${i}页</a>
                        </c:if>
                    </c:forEach>
                </c:when>
                <c:when test="${pages.pageNow==pages.pageTotal-1||pages.pageNow==pages.pageTotal}">
                    <c:forEach begin="${pages.pageTotal-4}" end="${pages.pageTotal}" var="i">
                        <c:if test="${pages.pageNow==i}">
                            第【${i}】页
                        </c:if>
                        <c:if test="${pages.pageNow!=i}">
                            <a href="../client?action=PageManage&pageNow=${i}&pageSize=${pages.pageSize}">第${i}页</a>
                        </c:if>
                    </c:forEach>
                </c:when>
                <c:otherwise>
                    <c:forEach begin="${pages.pageNow-2}" end="${pages.pageNow+2}" var="i">
                        <c:if test="${pages.pageNow==i}">
                            第【${i}】页
                        </c:if>
                        <c:if test="${pages.pageNow!=i}">
                            <a href="../client?action=PageManage&pageNow=${i}&pageSize=${pages.pageSize}">第${i}页</a>
                        </c:if>
                    </c:forEach>
                </c:otherwise>
            </c:choose>
        </c:otherwise>
    </c:choose>
    <input type="hidden" value="${pages.pageSize}" id="pageS"/><input type="hidden" value="${pages.pageTotal}" id="pageT"/>
    调到第<input type="text" id="skip" value="${pages.pageNow}"/>页 <button id="bu1">跳转</button>
</div>
<%@include file="../publicPages/footer.jsp"%>
</body>
</html>